package com.wangjialu.learner.stream.service.impl;

import cn.hutool.core.util.IdUtil;
import com.wangjialu.learner.stream.channel.ICustomMessageChannel;
import com.wangjialu.learner.stream.service.IMessageProvider;
import com.wangjialu.learner.stream.service.IMessageService;
import org.springframework.cloud.stream.annotation.EnableBinding;
import org.springframework.cloud.stream.messaging.Source;
import org.springframework.messaging.MessageChannel;
import org.springframework.messaging.support.MessageBuilder;

import javax.annotation.Resource;
import java.util.UUID;

/**
 * <p></p>
 *
 * @author WangJialu
 * @since 2021/6/25 0:37
 */
@EnableBinding({Source.class, ICustomMessageChannel.class})  //定义消息推送管道
public class MessageServiceImpl implements IMessageService, IMessageProvider {

    @Resource
    private MessageChannel output;  //消息发送通道

    @Override
    public String send() {
        String serial = UUID.randomUUID().toString();
        output.send(MessageBuilder.withPayload(serial).build());
        System.out.println("***********serial:" + serial);
        return serial;
    }

    @Override
    public String mySend() {
        String serial = IdUtil.objectId();
        output.send(MessageBuilder.withPayload(serial).build());
        System.out.println("***********serial:" + serial);
        return serial;
    }
}
